package com.k.kc.common;

/**
 * 错误码信息
 * @author kivil
 */
public final class ErrorCode {
    public final static int SUCCESS = 0;
    public final static int ERROR = 0;

    public enum Upload {
        DB_ERROR(-1,"DB_ERROR")
        ,PARAM_ERROR(-2,"PARAM_ERROR")
        ,DEFAULT(-99,"DEFAULT_ERROR");

        private int code;
        private String desc;

        Upload(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }
        public int getCode() {
            return code;
        }
        public String getDesc() {
            return desc;
        }
        public static String findStrByInt(int i){
            for (Upload item : Upload.values()) {
                if (item.getCode() == i) {
                    return item.getDesc();
                }
            }
            return DEFAULT.getDesc();
        }
        public static int findIntByStr(String str){
            for (Upload item : Upload.values()) {
                if (item.getDesc().equals(str.toUpperCase())) {
                    return item.getCode();
                }
            }
            return DEFAULT.getCode();
        }
    }

    public enum Download{
        DB_ERROR(-1,"DB_ERROR")
        ,PARAM_ERROR(-2,"PARAM_ERROR")
        ,DEFAULT(-99,"DEFAULT_ERROR");
        private int code;
        private String desc;

        Download(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }
        public int getCode() {
            return code;
        }
        public String getDesc() {
            return desc;
        }
        public static String findStrByInt(int i){
            for (Upload item : Upload.values()) {
                if (item.getCode() == i) {
                    return item.getDesc();
                }
            }
            return DEFAULT.getDesc();
        }
        public static int findIntByStr(String str){
            for (Upload item : Upload.values()) {
                if (item.getDesc().equals(str.toUpperCase())) {
                    return item.getCode();
                }
            }
            return DEFAULT.getCode();
        }
    }

}
